package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendPunchRecordAddDTO;
import org.jsola.hr.dto.AttendPunchRecordUpdateDTO;
import org.jsola.hr.entity.AttendPunchRecordDO;
import org.jsola.hr.query.AttendPunchRecordQuery;
import org.jsola.hr.service.IAttendPunchRecordService;
import org.jsola.hr.vo.AttendPunchRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendPunchRecordTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendPunchRecordService attendPunchRecordService;

    /**
     * 生成add测试数据
     * @return AttendPunchRecordAddDTO
     */
    public AttendPunchRecordAddDTO getAttendPunchRecordAddDTO(){
        AttendPunchRecordAddDTO attendPunchRecordAddDTO = new AttendPunchRecordAddDTO();
        attendPunchRecordAddDTO.setCompanyId(getRandomValue("varchar",32));
        attendPunchRecordAddDTO.setCompanyName(getRandomValue("varchar",100));
        attendPunchRecordAddDTO.setDeptId(getRandomValue("varchar",32));
        attendPunchRecordAddDTO.setDeptName(getRandomValue("varchar",100));
        attendPunchRecordAddDTO.setEmpInfoId(getRandomValue("varchar",32));
        attendPunchRecordAddDTO.setEmpInfoName(getRandomValue("varchar",50));
        attendPunchRecordAddDTO.setAttendPlanId(getRandomValue("varchar",32));
        attendPunchRecordAddDTO.setAttendPlanName(getRandomValue("varchar",100));
        attendPunchRecordAddDTO.setYear(getRandomValue("varchar",10));
        attendPunchRecordAddDTO.setMonth(getRandomValue("varchar",10));
        attendPunchRecordAddDTO.setDay(getRandomValue("varchar",10));
        attendPunchRecordAddDTO.setPunchType(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendPunchRecordAddDTO.setPunchRange(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendPunchRecordAddDTO.setRangeState(SafeKit.getInteger(getRandomValue("int",4)));
        attendPunchRecordAddDTO.setStandardTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        attendPunchRecordAddDTO.setPunchTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        attendPunchRecordAddDTO.setPunchStatus(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendPunchRecordAddDTO.setMinute(SafeKit.getInteger(getRandomValue("int",0)));
        attendPunchRecordAddDTO.setWorkTime(SafeKit.getInteger(getRandomValue("int",11)));
        attendPunchRecordAddDTO.setDecisionDesc(getRandomValue("varchar",255));
        attendPunchRecordAddDTO.setCoordinate(getRandomValue("varchar",255));
        attendPunchRecordAddDTO.setLocation(getRandomValue("varchar",255));
        attendPunchRecordAddDTO.setPunchWifi(getRandomValue("varchar",255));
        attendPunchRecordAddDTO.setPunchSource(SafeKit.getInteger(getRandomValue("int",0)));
        attendPunchRecordAddDTO.setIsCalibration(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        attendPunchRecordAddDTO.setIsMakeUp(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        attendPunchRecordAddDTO.setHisStandardTime(getRandomValue("varchar",32));
        attendPunchRecordAddDTO.setHisPunchTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        attendPunchRecordAddDTO.setHisPunchStatus(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendPunchRecordAddDTO.setPunchSerial(getRandomValue("varchar",32));
        return attendPunchRecordAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendPunchRecordUpdateDTO
     */
    public AttendPunchRecordUpdateDTO getAttendPunchRecordUpdateDTO(AttendPunchRecordVO attendPunchRecordVO){
        return attendPunchRecordService.selectDOById(attendPunchRecordVO.getId(), SITE_ID).to(AttendPunchRecordUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendPunchRecordQuery
     */
    public AttendPunchRecordQuery getAttendPunchRecordQuery() {
        AttendPunchRecordQuery attendPunchRecordQuery = new AttendPunchRecordQuery();
        List<AttendPunchRecordDO> attendPunchRecordDOList = attendPunchRecordService.list(new AttendPunchRecordDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendPunchRecordDOList)) {
            AttendPunchRecordDO attendPunchRecordDO = attendPunchRecordDOList.get(0);
            attendPunchRecordQuery = attendPunchRecordDO.to(AttendPunchRecordQuery.class);
            if (attendPunchRecordDO.getGmtCreate() != null) {
                attendPunchRecordQuery.setGmtCreateStart(DateKit.getBeforeDay(attendPunchRecordDO.getGmtCreate(),-1));
                attendPunchRecordQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendPunchRecordDO.getGmtCreate(),1));
            }
            if (attendPunchRecordDO.getGmtModified() != null) {
                attendPunchRecordQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendPunchRecordDO.getGmtModified(),-1));
                attendPunchRecordQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendPunchRecordDO.getGmtModified(),1));
            }
        }
        return attendPunchRecordQuery;
    }

    /**
     * 保存示例
     * @return AttendPunchRecordVO
     */
    public AttendPunchRecordVO saveAttendPunchRecordExample(){
        AttendPunchRecordAddDTO addDTO = this.getAttendPunchRecordAddDTO();
        AttendPunchRecordVO attendPunchRecordVO = attendPunchRecordService.save(addDTO,buildTokenUser());
        return attendPunchRecordVO;
    }


}

